package ai

import (
	"encoding/json"
	"fmt"

	facex "gobase/http_work_flow/label_center/ai/face"
	"gobase/rpcx_work_flow/rpcx_label_center"
)

// 数据转绘制
func Data2FaceMidentify(value *facex.RespFaceMidentify) (_frame rpcx_label_center.Frame, _err error) {
	var metas = make([]rpcx_label_center.Meta, 0)
	if len(value.Result.FaceList) == 0 {
		_err = fmt.Errorf("没有搜索到到人脸 %+v", value.Result)
		return
	}
	for _, v := range value.Result.FaceList {
		// var pens = []Pen{
		// 	{X: int64(v.Location.Left), Y: int64(v.Location.Top)},
		// 	{X: int64(v.Location.Left + float64(v.Location.Width)), Y: int64(v.Location.Top)},
		// 	{X: int64(v.Location.Left + float64(v.Location.Width)), Y: int64(v.Location.Top) + int64(v.Location.Height)},
		// 	{X: int64(v.Location.Left), Y: int64(v.Location.Top) + int64(v.Location.Height)},
		// }
		var meta = rpcx_label_center.Meta{
			X:      int64(v.Location.Left),
			Y:      int64(v.Location.Top),
			Remark: "多人脸搜索",
			TypeId: rpcx_label_center.IdScheme多人脸搜索,
			// ProtoWidth:  1920,
			// ProtoHeight: 1080,
			Rect: &rpcx_label_center.Rect{
				Width:  int64(v.Location.Width),
				Height: int64(v.Location.Height),
				Text:   v.UserInfoEx,
				Center: false,
			},
		}
		var userInfo facex.UserInfo
		err := json.Unmarshal([]byte(v.UserInfoEx), &userInfo)
		if err != nil {
			continue
		}
		meta.Rect.Text = userInfo.UserName
		metas = append(metas, meta)
	}

	_frame = rpcx_label_center.Frame{
		Metas: &metas,
		AbsoluteTime: &rpcx_label_center.AbsoluteTime{
			CenterUnixMs: int64(value.Timestamp * 1000),
			DurationMs:   2000,
		},
	}
	return
}
